package GiaoDien;

import it.unipr.ce.dsg.s2p.sip.Address;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.SpringLayout;
import javax.swing.border.EmptyBorder;

import Network.Class_GV_Send_Receive;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class frmBieuQuyetMoiRaKhoiNhom extends JFrame {
	Class_GV_Send_Receive peer;
	private JPanel contentPane;
	JLabel lblTimer = new JLabel();
	timerKickMember timerKick;
	int YKienBieuQuyet=1;
	/**
	 * Create the frame.
	 */
	public frmBieuQuyetMoiRaKhoiNhom(frm_ThaoLuanNhom frm ,String userNameKick,String ipKick,String userNameBeKick,String ipBeKick, long time) {
		
		
		timerKick=new timerKickMember(this);
		timerKick.runTime(time,this);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 560, 218);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new GridLayout());
		setContentPane(contentPane);
		
		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.CENTER);
		panel.setBackground(new Color(220,210,200));
		SpringLayout sl_panel = new SpringLayout();
		panel.setLayout(sl_panel);
		JLabel lblTitle = new JLabel("Title");
		sl_panel.putConstraint(SpringLayout.NORTH, lblTitle, 10, SpringLayout.NORTH, panel);
		sl_panel.putConstraint(SpringLayout.EAST, lblTitle, -151, SpringLayout.EAST, panel);
		lblTitle.setBounds(37, 5, 334, 51);
		
		lblTitle.setText("<html><font size = 6 color = BLUE align=center>Mời thành viên ra khỏi nhóm</font></html>");
		panel.add(lblTitle, BorderLayout.NORTH);
		
		
		
		JLabel lblThongbao = new JLabel();
		sl_panel.putConstraint(SpringLayout.NORTH, lblThongbao, 19, SpringLayout.SOUTH, lblTitle);
		sl_panel.putConstraint(SpringLayout.WEST, lblThongbao, 10, SpringLayout.WEST, panel);
		lblThongbao.setBounds(347, 19, 0, 0);
		lblThongbao.setText("<html><font size = 4 color = BLACK >"+userNameKick+" đang yêu cầu biểu quyết để mời "+userNameBeKick+" ra khỏi nhóm. </font></html>");
		panel.add(lblThongbao);
		
		JButton btnAgree = new JButton();
		sl_panel.putConstraint(SpringLayout.NORTH, btnAgree, 24, SpringLayout.SOUTH, lblThongbao);
		sl_panel.putConstraint(SpringLayout.WEST, btnAgree, 153, SpringLayout.WEST, panel);
		sl_panel.putConstraint(SpringLayout.SOUTH, btnAgree, 53, SpringLayout.SOUTH, lblThongbao);
		sl_panel.putConstraint(SpringLayout.EAST, btnAgree, -290, SpringLayout.EAST, panel);
		btnAgree.setBounds(94, 218, 75, 23);
		btnAgree.setText("Đồng ý");
		btnAgree.setActionCommand("Agree");
		final String ipKicker=ipKick;
		btnAgree.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				YKienBieuQuyet=1;
				peer.SendFedbackKickMember(new Address(ipKicker), YKienBieuQuyet);
				CloseForm();
			}
		});
		panel.add(btnAgree, BorderLayout.SOUTH);
		
		JButton btnDisAgree = new JButton();
		sl_panel.putConstraint(SpringLayout.NORTH, btnDisAgree, 24, SpringLayout.SOUTH, lblThongbao);
		sl_panel.putConstraint(SpringLayout.WEST, btnDisAgree, 38, SpringLayout.EAST, btnAgree);
		sl_panel.putConstraint(SpringLayout.SOUTH, btnDisAgree, 0, SpringLayout.SOUTH, btnAgree);
		sl_panel.putConstraint(SpringLayout.EAST, btnDisAgree, -161, SpringLayout.EAST, panel);
		btnDisAgree.setBounds(250, 218, 67, 23);
		btnDisAgree.setText("Phản đối");
		btnDisAgree.setActionCommand("DisAgree");
		btnDisAgree.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				YKienBieuQuyet=0;
				peer.SendFedbackKickMember(new Address(ipKicker), YKienBieuQuyet);
				CloseForm();
			}
		});
		panel.add(btnDisAgree);
		
		
		sl_panel.putConstraint(SpringLayout.NORTH, lblTimer, 13, SpringLayout.NORTH, lblTitle);
		sl_panel.putConstraint(SpringLayout.WEST, lblTimer, 49, SpringLayout.EAST, lblTitle);
		panel.add(lblTimer);
		
		
		

	}
	
	public void ThongBao(String sThongBao)
	{
		Object[] optionsNoDN = {"Đóng"};
		JOptionPane.showMessageDialog(new JPanel(),sThongBao,"thong bao nha",
			    JOptionPane.OK_OPTION);
	}
	
	void CloseForm(){
		this.setVisible(false);
	}
	
	public void SetTimeText(String s){
		lblTimer.setText(s);
	}
}
